#include "DBFileBufPageManager.h"

int maxPid = 0;

DBFileBufPageManager::DBFileBufPageManager(void)
{

}

DBFileBufPageManager::~DBFileBufPageManager(void)
{

}

/**
* Funtion Description : Open A file,
* Create System table
* @para char* filename: 
* file name
* by Author: Jimmy
*/
void DBFileOpenFile(char* filename)
{

}


/**
* Funtion Description : Open A page
* @para int pid:
* page id
* @para DBFileSystem* dbFileSystem
* DBFileSystem need to be read in
* @return char*
* header of this page
* by Author:Jimmy
*/
DBBufPage* DBFileBufPageManager::DBFileOpenPage(int pid)
{
	if(pid2page.find(pid) != pid2page.end())
	{
		return pid2page[pid];
	}
	else
		ASSERT(false);	// invalid pid
}

/**
* Funtion Description : Alloc a new page in currently open page
* by Author: Jimmy
* @para int& pid: this is a return value, which is the page id of 
* new alloced page
* @char*& pageHead: this is a return value, which is the head of 
* new page
*/
void DBFileBufPageManager::DBFileAllocPage(int& pid, DBBufPage*& pageHead)
{
	pid = maxPid ++;
	pid2page[pid] = new DBBufPage;
	pageHead = pid2page[pid];
}

/**
* Funtion Description : Delete A page(mark it unused)
* by Author: Jimmy
* @para int pid
* page id
*/
void DBFileBufPageManager::DBFileDeletePage(int pid)
{
	pid2page.erase(pid);
}

/**
* Funtion Description : Close a page
* @para int pid
* page id
* by Author: Jimmy
*/
void DBFileBufPageManager::DBFileClosePage(int pid)
{

}

/**
* Funtion Description :Close the currently opened file
* by Author: Jimmy
*/
void DBFileBufPageManager::DBFileCloseFile()
{

}
